//
//  WmcCloudDateView.swift
//  YPWatermarkCamera
//
//  Created by 周诗松 on 2022/8/2.
//

import UIKit

class WmcCloudDateView: WmcBaseView {
    // Internal

    var dateModel: WmcMediaTakePhotoDayModel?

    var dateClosure: ((WmcMediaTakePhotoDayModel) -> Void)?

    override func makeUI() {
        addSubview(dateBtn)

        dateBtn.snp.makeConstraints { make in
            make.width.equalTo(150)
            make.height.equalTo(24)
            make.center.equalToSuperview()
        }
    }

    override func bindViewAction() {
        dateBtn.yp.addEvent { [weak self] _ in
            guard let weakSelf = self else { return }
            if let dateModel = weakSelf.dateModel {
                weakSelf.dateClosure?(dateModel)
            }
        }
    }

    func setDate(_ date: WmcMediaTakePhotoDayModel?) {
        dateModel = date

        if let date = date {
            let dateStr: String = "查看\(date.month)月\(date.day)日照片"
            dateBtn.setTitle(dateStr, for: .normal)
        } else {
            dateBtn.isHidden = true
        }
    }

    // Private

    private lazy var dateBtn: UIButton = {
        let btn = UIButton(type: .custom)
        btn.setTitle("查看1月2日照片", for: .normal)
        btn.setTitleColor(.wmc_mainTheme, for: .normal)
        btn.titleLabel?.font = 16.wmc_font
        btn.setImage("arrow_bottom".wmc_image.yp.set(tintColor: UIColor.wmc_mainTheme), for: .normal)
        btn.titleEdgeInsets = UIEdgeInsets(top: 0, left: -20, bottom: 0, right: 15)
        btn.imageEdgeInsets = UIEdgeInsets(top: 0, left: 135, bottom: 0, right: 0)
        return btn
    }()
}
